package huzh.foundation.pool.threadpool;

import huzh.foundation.pool.objectpool.IObject;

import java.io.Serializable;

/**
 *<p>title:AbstractTask</p>
 *<p>description:</p>
 * @since 2014-6-7
 * @author huzh
 * @version 1.0
 */
public abstract class AbstractTask implements ParaRunnable, Runnable, IObject, Serializable{
    /**serialVersionUID*/
    private static final long serialVersionUID = -4344068827180954029L;
    /**result*/
    private Object result = null;
    /**finished*/
    private boolean finished = false;

    /**
     * 
     */
    public void run() {
        run(null);
    }
    /**
     * 
     */
    public abstract void reset();

    /**
     * @param paramObject
     */
    public abstract void run(Object paramObject);

    /**
     * @return
     */
    public Object getResult() {
        return this.result;
    }

    /**
     * @param obj
     */
    protected void setResult(Object obj) {
        this.result = obj;
    }

    /**
     * @return
     */
    public boolean isDone() {
        return this.finished;
    }

    /**
     * @param b
     */
    protected void setDone(boolean b) {
        this.finished = b;
    }

    /**
     * @param t
     */
    protected void delay(long t) {
        try {
            Thread.currentThread(); Thread.sleep(t);
        } catch (Exception ex) {
            System.out.println(ex);
        }
    }

    /**
     * 
     */
    public void join() {
        while (!isDone())
            delay(10L);
    }
}
